home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Magazine / Online / httpproxy / src / service.c < prev    next >
C/C++ Source or Header  |  1996-08-20  |  4KB  |  150 lines

  1. /*(( "Header" */
  2. /*
  3.  * $Id: service.c,v 1.4 1996/08/20 17:36:43 mshopf Exp mshopf $
  4.  *
  5.  * (c) 1995-96 Matthias Hopf
  6.  *
  7.  * Log file functions for httpproxy.
  8.  *
  9.  */
  10.  
  11. /*
  12.  * $Log: service.c,v $
  13.  * Revision 1.4  1996/08/20  17:36:43  mshopf
  14.  * new queuing mode.
  15.  *
  16.  * Revision 1.3  1996/08/11  22:25:15  mshopf
  17.  * reworked debug messages.
  18.  *
  19.  * Revision 1.2  1996/06/06  23:01:23  mshopf
  20.  * added mode service.
  21.  * url logging bug fix.
  22.  *
  23.  * Revision 1.1  1996/06/03  04:17:23  mshopf
  24.  * Initial revision
  25.  *
  26.  */
  27.  
  28.  
  29. /*)) */
  30. /*(( "Includes" */
  31.  
  32. #include "httpproxy.h"
  33.  
  34. #include <string.h>
  35.  
  36. #define MAX_SERVICELEN 16       /* Maximum service length including trailing 0x00 */
  37.  
  38. /*)) */
  39.  
  40. /*(( "ConfigService ()" */
  41.  
  42. /* scan Object name for configuration commands */
  43.  
  44. int    ConfigService (request_t *Req, const char *Object)
  45. {
  46.     switch (Object[1]) {
  47.     case 'o':                         /* online mode */
  48.     if (Object[2] == '0' || Object[2] == '1')
  49.     {
  50.         OffLine = '1' - Object[2];
  51.         if (OffLine)
  52.         ShutdownConnects ();                /* remove working requests */
  53.         else
  54.         CheckGetQueued (TRUE);              /* Force rescan of queued URLs */
  55.         ErrToReq (Req, 202, -1, "Configuration: Online state", OffLine ? "HttpProxy is now in offline state." :
  56.                                          (GetQueued ? "HttpProxy is now in online state and getting queued URLs." :
  57.                                               "HttpProxy is now in online state") , Object);
  58.         return (2);
  59.     }
  60.     break;
  61.  
  62.     case 'g':                         /* getting queued URLs */
  63.     if (Object[2] == '0' || Object[2] == '1')
  64.     {
  65.         GetQueued = Object[2] - '0';
  66.         if (! OffLine)
  67.         CheckGetQueued (TRUE);              /* Force rescan of queued URLs */
  68.         ErrToReq (Req, 202, -1, "Configuration: Get queued URLs state", GetQueued ? (OffLine ? "HttpProxy will get queued URLs as soon as it is online." :
  69.                                                    "HttpProxy will get queued URLs now.") :
  70.                                             "HttpProxy will not get any queued URLs automatically.", Object);
  71.         return (2);
  72.     }
  73.     break;
  74.  
  75.     default:
  76.     break;
  77.     }
  78.     ErrToReq (Req, 400, 0, "Unknown configuration service", "The requested configuration service is not supported or unknown.", Object);
  79.     return (2);
  80. }
  81.  
  82. /*)) */
  83. /*(( "ModeService ()" */
  84.  
  85. /* scan Object name for mode commands */
  86.  
  87. int    ModeService (request_t *Req, const char *Object)
  88. {
  89.     switch (Object[1]) {
  90.     case 'r':                         /* reload mode */
  91.     if (Object[2] == '0' || Object[2] == '1')
  92.     {
  93.         AlwaysReload = Object[2] - '0';
  94.         ErrToReq (Req, 202, -1, "Mode: Reload", AlwaysReload ? "HttpProxy is now in reload mode. No requests will be served from the cache." :
  95.                                    "HttpProxy is now in standard mode.", Object);
  96.         return (2);
  97.     }
  98.     break;
  99.  
  100.     case 'q':                         /* queue mode */
  101.     if (Object[2] == '0' || Object[2] == '1')
  102.     {
  103.         QueueMode = Object[2] - '0';
  104.         ErrToReq (Req, 202, -1, "Mode: Queuing", QueueMode ? "HttpProxy is now in queuing mode. While offline HttpProxy will queue URL requests "
  105.                                  "that are not in the cache." :
  106.                                  "HttpProxy will not queue any expired cache entries now. New followed links will not "
  107.                                  "be queued, too. However, reload requests will still queue the current document.", Object);
  108.         return (2);
  109.     }
  110.     break;
  111.  
  112.     default:
  113.     break;
  114.     }
  115.     ErrToReq (Req, 400, 0, "Unknown mode service", "The requested mode service is not supported or unknown.", Object);
  116.     return (2);
  117. }
  118.  
  119. /*)) */
  120. /*(( "ScanService ()" */
  121.  
  122. /* The main function: scan Object name for commands */
  123. /* return values: see ScanUrl() in httpproxy.c */
  124.  
  125. int    ScanService (request_t *Req, const char *Object)
  126. {
  127.     static char Obj [MAX_SERVICELEN];
  128.  
  129.     debug (D_REQUEST, ("%02d: service '%s'\n", Req-Requests, Object));
  130.  
  131.     strncpy (Obj, Object, MAX_SERVICELEN);     /* will be needed for logging afterwards (hacky...) */
  132.     Obj [MAX_SERVICELEN-1] = '\0';
  133.  
  134.     switch (Obj[0]) {
  135.     case 'c':                       /* change Configuration */
  136.     return (ConfigService (Req, Obj));
  137.     case 'm':                       /* change Mode */
  138.     return (ModeService (Req, Obj));
  139.     case 'l':                       /* List objects */
  140.     case 'r':                       /* Remove entry */
  141.     case 'v':                       /* Mark entry as valid */
  142.     default:
  143.     break;
  144.     }
  145.     ErrToReq (Req, 400, 0, "Unknown service", "The requested service is not supported or unknown.", Obj);
  146.     return (2);
  147. }
  148.  
  149. /*)) */
  150.